/**
 * 工具函数
 */

/**
 * 生成一个随机数
 * @param {number} min 最小值
 * @param  {number} max 最大值
 * @returns {number} 范围随机数
 */
export function randomNum(min: number, max: number): number {
  return Math.floor(Math.random() * (max - min) + min);
}

/**
 * 生成一个随机的颜色
 * @param {number} min 最小值
 * @param  {number} max 最大值
 * @returns {string}
 */
export function randomColor(min: number, max: number): string {
  const r = randomNum(min, max);
  const g = randomNum(min, max);
  const b = randomNum(min, max);
  return 'rgb(' + r + ',' + g + ',' + b + ')';
}

/**
 * 检测设备类型（mobile返回 true ，反之）
 * @returns Boolean
 */
export function deviceDetection(): boolean {
  const t = navigator.userAgent.toLowerCase();
  const n = (t.match(/midp/i) as unknown as string) === 'midp';
  const e = t.match(/ucweb/i) as unknown as string;
  const r = t.match(/android/i) as unknown as string;
  const o = t.match(/iphone os/i) as unknown as string;
  const s = t.match(/windows ce/i) as unknown as string;
  const i = t.match(/rv:1.2.3.4/i) as unknown as string;
  const a = t.match(/windows mobile/i) as unknown as string;
  return Boolean(n || e || r || o || s || i || a);
}
